R graphs

Explore and analize data visually

Dr. Peng Zhao (✉ peng.zhao@xjtlu.edu.cn)

Department of Health and Environmental Sciences
Xi’an Jiaotong-Liverpool University

1 Prerequisites

  1. Basic Knowledge in R.
  2. Installation of R and RStudio IDE (instructions in English and in Chinese
  3. Packages

2 Objectives

Don’t be too ambitious.

  1. Know what graphs R could produce (R Graph Gallery).
  2. Know four popular R systems for graphing, including basic packages, ggplot2, plotly, and rgl.
  3. Reproduce the graphs shown in this workshop by yourself.

3 What R can plot

3.1 Traditional

:width 80%

:width 100%

3.2 Interactive

3.3 Animated

3.4 Geographical

3.5 Amazing

3.6 Ubiquitous

4 Graph components

  • Graph area

    • Plotting area
    • Axes
    • Legends
  • Figure number + caption (not required in this module)

5 Packages

5.1 Base R

Cat. Function Usage
High level plot() x-y scatter plot. Relationship between two variables.
pairs()
symbols()
hist()
curve()
barplot()
boxplot()
coplot()
dotchart()
stripchart()
image()
contour()
Low level lines()
points()
abline()
axis()
legend()
text()
mtext()
layout()

5.2 ggplot2

ggplot() +      # mandatory: data mapping
  geom_xxx() +  # mandatory: geometry shape
  coordinate_xxx() +  
  theme() +          
  facet_xxx() +      
  ...
Function Usage
geom_point() x-y scatter plot. Relationship between two variables.
geom_line()
geom_bar()
geom_histogram()
geom_freqpoly()
geom_density()
geom_boxplot()
geom_bin2d()
geom_density2d()
geom_contour()
geom_abline()
geom_text()
geom_errorbar()
geom_polygon()
geom_rect()
geom_smooth()

6 Graphical User Interface

library(GrapheR)
run.GrapheR()
library(Rcmdr)
ggplotgui::ggplot_shiny()
library(Deducer)
JGR()

7 Further readings